#!/usr/bin/env python
# encoding: utf-8

print "cwunicode"

# built-in stuff
import unittest

# stuff to test
from cwunicode import *

class LookupTest(unittest.TestCase):
	
	def testOneCharacter(self):
		self.assertEqual(dict(main({"context":{"selection":"AMPERSAND"},"meta":{"antefix":""}}))["replace"],"&")
		self.assertEqual(dict(main({"context":{"selection":"ampersand"},"meta":{"antefix":""}}))["replace"],"&")
		self.assertEqual(dict(main({"context":{"selection":"LATIN CAPITAL LETTER AE"},"meta":{"antefix":""}}))["replace"],u"Æ")
	
	def testSeveralCharacters(self):
		self.assertEqual(dict(main({"context":{"selection":"POUND SIGN LATIN SMALL LETTER E WITH GRAVE GRAVE ACCENT VULGAR FRACTION ONE QUARTER"},"meta":{"antefix":""}}))["replace"],u"£ è ` ¼")
	
	def testNoise(self):
		self.assertEqual(dict(main({"context":{"selection":"foo bar"},"meta":{"antefix":""}}))["replace"],"foo bar")
	
	def testSeveralCharactersWithSomeNoise(self):
		self.assertEqual(dict(main({"context":{"selection":"POUND SIGN LATIN SMALL LETTER E foo bar WITH GRAVE GRAVE ACCENT VULGAR FRACTION ONE QUARTER"},"meta":{"antefix":""}}))["replace"],u"£ e foo bar WITH GRAVE ` ¼")
	
	def testEmptyString(self):
		self.assertEqual(dict(main({"context":{"selection":""},"meta":{"antefix":""}}))["replace"],"")
	
	def testCannotCombine(self):
		self.assertEqual(dict(main({"context":{"selection":"COMBINING CEDILLA LATIN CAPITAL LETTER C"},"meta":{"antefix":""}}))["replace"],u"\u0327 C")
	
	def testCodes(self):
		self.assertEqual(dict(main({"prefs":{"cwUnicode_decimal":True},"context":{"selection":"0X4E86 0x4e86 20102"},"meta":{"antefix":""}}))["replace"],u"了 了 了")
		self.assertEqual(dict(main({"prefs":{"cwUnicode_decimal":False},"context":{"selection":"0X4E86 0x4e86 20102"},"meta":{"antefix":""}}))["replace"],u"了 了 20102")

if __name__ == '__main__':
	unittest.main()
